package hot;

public class Num494 {
    int count = 0;
    public int findTargetSumWays(int[] nums, int target) {
        dfs(nums,target,0,0);
        return count;
    }
    public void dfs(int[] nums,int target,int sum,int depth) {
        if(depth == nums.length) {
            if(sum == target) {
                count++;
                return;
            }else {
                return;
            }
        }
        for(int i = 0; i < 2; i++) {
            if(i == 0) sum += nums[depth];
            else sum -= nums[depth];
            dfs(nums,target,sum,depth + 1);
            if(i == 0) sum -= nums[depth];
            else sum += nums[depth];
        }
    }
}
